<template>
  <div class="company-user">
    <index-breadcrumb :breadcrumb-list="breadcrumbList" :isShow="false"></index-breadcrumb>
    <company-user-list :operation-list="operationList" v-if="type == 1" @changeType="changeType"></company-user-list>
    <user-msg :operation-list="operationList" v-if="type == 2" :current-item="currentItem" @goBackOne="changeOneType"></user-msg>
  </div>
</template>

<script>
import CompanyUserList from "@/views/sys/companyUser/includes/CompanyUserList";
import UserMsg from "@/views/sys/companyUser/includes/UserMsg";

export default {
  name: "CompanyUser",
  components: {
    CompanyUserList,
    UserMsg,
  },
  data() {
    return {
      operationList: [],
      breadcrumbList: [
        {
          title: "系统管理"
        },
        {
          title: "账号管理"
        }
      ],
      type: 1,
      currentItem: null,
    };
  },
  created() {
    this.getOperationList();
  },
  methods: {
    changeOneType(){
      this.currentItem = null
      this.type = 1
    },
    changeType(val){
      this.currentItem = val
      this.type = 2
    },
    getOperationList() {
      this.$store.state.permissionList.forEach(item => {
        const [itemName] = item.permission.split(":");
        if (itemName === "managerUser") {
          this.operationList = item.list.map(listItem => {
            return listItem.permission.split(":")[1];
          });
        }
        if (itemName === "permission") {
          item.list.some(listItem => {
            const listItemType = listItem.permission.split(":")[1];
            if (listItemType === "edit") {
              this.operationList.push("permission:edit");
              return true;
            }
            return false;
          });
        }
      });
    }
  }
};
</script>

<style lang="sass" scoped>

</style>
